#!/usr/bin/python3.6
# -*- coding: UTF-8 -*-


import os
import time
import argparse
from http.server import HTTPServer, CGIHTTPRequestHandler

workspace_path = os.getcwd()
root_path = workspace_path[0:workspace_path.rfind(os.sep)] + os.sep


def parse_args():
    parser = argparse.ArgumentParser(description='ipa下载服务器.\n')

    parser.add_argument('-port',
                        default=8000,
                        dest='port',
                        help='端口', type=str, required=False)

    parser.add_argument('-folder_path',
                        default='/Volumes/ShareHistory/ios/web_workspace/resources',
                        dest='folder_path',
                        help='路径', type=str, required=False)

    args = parser.parse_args()
    return args


def run():
    app_args = parse_args()
    port = app_args.port
    folder_path = app_args.folder_path
    os.chdir(folder_path)
    httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
    print("Starting simple_httpd on port: " + str(httpd.server_port))
    httpd.serve_forever()


if __name__ == '__main__':
    run()
